home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / interface / OutputFormat.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  792b  |  38 lines

  1. #include "stdafx.h"
  2.  
  3. #include "OutputFormat.h"
  4.  
  5.  
  6. // This function adds delimiters by thousands base.
  7. // Delimiter based on user locale settings.
  8. CString makeUserFriendlyString(__int64 val)
  9. {
  10.     int delimLen = ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, NULL, 0);
  11.  
  12.     CString delimStr;
  13.     delimStr.Preallocate(delimLen);
  14.  
  15.     ::GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, delimStr.GetBuffer(), delimLen);
  16.     delimStr.ReleaseBuffer();
  17.  
  18.     CString str;
  19.     str.Format(_T("%I64d"), val);
  20.  
  21.     CString result_str;
  22.     int dec_count = 2 - ((str.GetLength() + 2) % 3);
  23.     for (int idx = 0; idx < str.GetLength(); idx++)
  24.     {
  25.         if (dec_count > 2)
  26.         {
  27.             dec_count = 0;
  28.             result_str += delimStr;
  29.         }
  30.         result_str += str[idx];
  31.         dec_count++;
  32.     }
  33.     return result_str;
  34. }
  35.  
  36.  
  37.  
  38.